<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <!-- import CSS -->
  <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
  <style>
    body{background-color: rgb(241,242,243)}
    .el-header{background-color: white}
    #footer_center h3{color: white}
    #footer_center p{margin: 0}
    .title_p{
      height: 40px;
      overflow: hidden;
      /*设置省略号相关样式*/
      display: -webkit-box;
      -webkit-line-clamp:2; /*设置显示行数*/
      -webkit-box-orient: vertical;/*设置纵向排列*/
    }
  </style>
</head>
<body>
<div id="app">
  <el-container>
    <my-header></my-header>
    <el-main style="width: 1200px;margin: 0 auto">
      <!--轮播图开始-->
      <el-carousel height="350px">
        <el-carousel-item v-for="item in bannerArr">
          <img :src="item.imgUrl" width="100%">
        </el-carousel-item>
      </el-carousel>
      <!--轮播图结束-->
      <!--烘焙食谱开始-->
        <el-row style="background-color: white">
          <el-col span="3">
            <p style="font-size: 28px;margin: 15px">烘焙食谱</p>
          </el-col>
          <el-col span="21">
            <el-menu mode="horizontal" default-active="0" @select="selectRecipe"
                     active-text-color="orange">
              <el-menu-item index="0">全部</el-menu-item>
              <el-menu-item v-for="(c,i) in recipeCategoryArr" :key="i" :index="c.id">{{c.name}}</el-menu-item>
            </el-menu>
          </el-col>
        </el-row>
        <el-row gutter="20">
          <el-col span="6" style="margin: 10px 0" v-for="item in recipeArr">
            <el-card>
              <a :href="'/detail.html?id='+item.id">
                <img :src="item.imgUrl" width="100%" height="145">
                <p class="title_p">{{item.title}}</p>
              </a>
              <el-row>
                <el-col span="4" >
                  <el-avatar size="small" :src="item.userImgUrl"></el-avatar>
                </el-col>
                <el-col span="10">{{item.nickname}}</el-col>
                <el-col span="10">
                  <span style="float: right;font-size: 12px;color: #666">{{item.categoryName}}</span>
                </el-col>
              </el-row>
            </el-card>
          </el-col>
        </el-row>
        <div style="text-align: center">
          <el-button @click="location.href='/list.html?type=1'">点击加载更多食谱</el-button>
        </div>
      <!--烘焙食谱结束-->

      <!--烘焙视频开始-->
      <el-row style="background-color: white">
        <el-col span="3">
          <p style="font-size: 28px;margin: 15px">烘焙视频</p>
        </el-col>
        <el-col span="21">
          <el-menu mode="horizontal" default-active="0" @select="selectVideo"
                   active-text-color="orange">
            <el-menu-item index="0">全部</el-menu-item>
            <el-menu-item v-for="c in videoCategoryArr" :index="c.id">{{c.name}}</el-menu-item>

          </el-menu>
        </el-col>
      </el-row>
      <el-row gutter="20">
        <el-col span="6" style="margin: 10px 0" v-for="item in videoArr">
          <el-card>
            <a :href="'/detail.html?id='+item.id">
              <img :src="item.imgUrl" width="100%" height="145">
              <p class="title_p">{{item.title}}</p>
            </a>
            <el-row>
              <el-col span="4" >
                <el-avatar size="small" :src="item.userImgUrl"></el-avatar>
              </el-col>
              <el-col span="10">{{item.nickname}}</el-col>
              <el-col span="10">
                <span style="float: right;font-size: 12px;color: #666">{{item.categoryName}}</span>
              </el-col>
            </el-row>
          </el-card>
        </el-col>
      </el-row>
      <div style="text-align: center">
        <el-button @click="location.href='/list.html?type=2'">点击加载更多视频</el-button>
      </div>
      <!--烘焙视频结束-->
      <!--行业资讯开始-->
      <el-row style="background-color: white">
        <el-col span="3">
          <p style="font-size: 28px;margin: 15px">行业资讯</p>
        </el-col>
        <el-col span="21">
          <el-menu mode="horizontal" default-active="0" @select="selectInfo"
                   active-text-color="orange">
            <el-menu-item index="0">全部</el-menu-item>
            <el-menu-item v-for="c in infoCategoryArr" :index="c.id">{{c.name}}</el-menu-item>

          </el-menu>
        </el-col>
      </el-row>
      <el-row gutter="20">
        <el-col span="6" style="margin: 10px 0" v-for="item in infoArr">
          <el-card>
            <a :href="'/detail.html?id='+item.id">
              <img :src="item.imgUrl" width="100%" height="145">
              <p class="title_p">{{item.title}}</p>
            </a>
            <el-row>
              <el-col span="4" >
                <el-avatar size="small" :src="item.userImgUrl"></el-avatar>
              </el-col>
              <el-col span="10">{{item.nickname}}</el-col>
              <el-col span="10">
                <span style="float: right;font-size: 12px;color: #666">{{item.categoryName}}</span>
              </el-col>
            </el-row>
          </el-card>
        </el-col>
      </el-row>
      <div style="text-align: center">
        <el-button @click="location.href='/list.html?type=3'">点击加载更多资讯</el-button>
      </div>
      <!--行业资讯结束-->
    </el-main>
    <el-footer style="background-color: #2f3234;height: 280px;padding: 50px 0">
        <div style="width: 1200px;margin: 0 auto;text-align: center;color: #666">
          <el-row gutter="20">
            <el-col span="8">
              <img src="imgs/icon.png">
              <p>教程灵感就看烘焙坊</p>
              <p>烘焙行业网络社区平台</p>
              <p>全国百城上千个职位等你来</p>
            </el-col>
            <el-col id="footer_center" span="8">
              <el-row gutter="20">
                <el-col span="8">
                  <h3>关于我们</h3>
                  <p>烘焙学院</p><p>烘焙食谱</p>
                  <p>分类信息</p><p>求职招聘</p><p>社区交流</p>
                </el-col>
                <el-col span="8">
                  <h3>服务与支持</h3>
                  <p>练习我们</p><p>广告投放</p>
                  <p>用户协议</p><p>友情链接</p><p>在线反馈</p>
                  <p>我发投稿</p>
                </el-col>
                <el-col span="8">
                  <h3>底部导航</h3>
                  <p>Archiver</p><p>手机版</p><p>小黑屋</p>
                </el-col>
              </el-row>
            </el-col>
            <el-col span="8">
              <p style="font-size: 60px;margin: 0">
                <span style="color: orange">烘焙</span>坊
              </p>
              <p>烘焙行业网络社区平台</p>
            </el-col>
          </el-row>
        </div>
    </el-footer>
  </el-container>
</div>
</body>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<!--引入Axios框架-->
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<script src="js/header.js"></script>
<script>
  let v = new Vue({
    el: '#app',
    data: function() {
      return {
        recipeArr:[],
        videoArr:[],
        infoArr:[],
        recipeCategoryArr:[],
        videoCategoryArr:[],
        infoCategoryArr:[],
        bannerArr:[]
      }
    },
    methods:{
      selectRecipe(key,keyPath){
        v.loadContent(1,key);
      },
      selectVideo(key,keyPath){
        v.loadContent(2,key);
      },
      selectInfo(key,keyPath){
        v.loadContent(3,key);
      },
      loadSubCategories(){
        //请求二级分类
        axios.get("/v1/categories/1/sub").then(function (response) {
          if (response.data.code==1){
            v.recipeCategoryArr = response.data.data;
          }
        })
        axios.get("/v1/categories/2/sub").then(function (response) {
          if (response.data.code==1){
            v.videoCategoryArr = response.data.data;
          }
        })
        axios.get("/v1/categories/3/sub").then(function (response) {
          if (response.data.code==1){
            v.infoCategoryArr = response.data.data;
          }
        })
      },
      loadContent(type,categoryId){
        axios.get("/v1/contents/"+type+"/"+categoryId+"/index").then(function (response) {
          if (response.data.code==1){
            switch (type) {
              case 1://食谱
                    v.recipeArr = response.data.data;
                    break;
              case 2://视频
                v.videoArr = response.data.data;
                break;
              case 3://资讯
                v.infoArr = response.data.data;
                break;
            }
          }
        })
      }
    },
    created:function () {//created方法会在Vue对象初始化过程中自动触发
      //一进入页面时触发的代码写在此处
      axios.get("/v1/banners/").then(function (response) {
        if (response.data.code==1){
          v.bannerArr = response.data.data;
        }
      })
      //请求二级分类数据
      this.loadSubCategories();
      //请求文章内容   0代表全部
      this.loadContent(1,0);
      this.loadContent(2,0);
      this.loadContent(3,0);

    }
  })
</script>
</html>